/*var signupValidator = (function() {

	var regexp = {
		USERNAME : /^[a-zA-Z0-9]+$/,
		PASSWORD : /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$/
	};
	
	var id = {
		USERNAME : "username",
		PASSWORD : "password",
		FIRSTNAME : "firstname",
		LASTNAME : "lastname"
	};

	var signupValidator = {};
	
	signupValidator.validateForm = function(form) {
		var username = form[id.USERNAME];
		var password = form[id.PASSWORD];
		
		if(this.isValidUsername(username) && this.isValidPassword(password)) {
			return true;
		} else {
			return false;
		}
	};

	signupValidator.isValidUsername = function(name) {
		return regexp.USERNAME.test(name);
	};

	signupValidator.isValidPassword = function(password) {
		return regexp.PASSWORD.test(password);
	};

	return signupValidator;
	
})();
	
var validate = function(){
	var form = document.forms["subscriber"];

	form.submit(function(event) {
		if(signupValidator.validateForm(form)) {
			return true;
		}else {
			var incUser = document.findElementById("IncUsername").style.display='block';
			event.preventDefault();
		}
	});
};*/

var regexp = {
		USERNAME : /^[a-zA-Z0-9_]+$/,
		PASSWORD : /^{4,}$/,
		FIRSTNAME : /^[a-zA-Z]+$/,
		SECONDNAME : /^[a-zA-Z]+$/,
	};

function isValidUsername(form) {
	var username = form["username"].value;
	if(username == "" || username == null){
		return false;
	} 
	return regexp.USERNAME.test(username);
}

function isValidPassword(form) {
	var password = form["password"].value;
	if(password == "" || password == null){
		return false;
	} 
	return regexp.PASSWORD.test(password);
}

function isValidFirstname(form) {
	var firstname = form["firstname"].value;
	if(firstname == "" || firstname == null){
		return false;
	} 
	return regexp.FIRSTNAME.test(firstname);
}

function isValidLastname(form) {
	var lastname = form["lastname"].value;
	if(lastname == "" || lastname == null){
		return false;
	} 
	return regexp.FIRSTNAME.test(lastname);
}

function validate(){
	var form = document.forms["subscriber"];
	var isValid = true;
	if(!isValidUsername(form)){
		isValid = false;
		document.getElementById("incUsername").style.display='block';
	} else {
		document.getElementById("incUsername").style.display='none';
	}
	
	if(!isValidPassword(form)){
		isValid = false;
		document.getElementById("incPassword").style.display='block';
	} else {
		document.getElementById("incUsername").style.display='none';
	}
	
	if(!isValidFirstname(form)){
		isValid = false;
		document.getElementById("incFirstname").style.display='block';
	} else {
		document.getElementById("incUsername").style.display='none';
	}
	
	if(!isValidLastname(form)){
		isValid = false;
		document.getElementById("incLastname").style.display='block';
	} else {
		document.getElementById("incUsername").style.display='none';
	}
	
	if(isValid == false){
		//event.preventDefault();
		return false;
	}
	
	form.submit;
	
}

